package ljl.alg.wangzheng_camp.round1.sort;

public class _offer_21_odd_before_even {
    
    /**
     * 我都不爱写，太简单
     *
     * 双指针！差点被搞死
     * */
    public int[] exchange(int[] nums) {
        int len = nums.length;
        int odd = 0, even = len - 1;
        while (odd < even) {
            // 我居然写成 odd < len 和 even < len 了，
            // 我是怎么想的？
            while (odd < even && (nums[odd] & 1) == 1) odd++;
            while (odd < even && (nums[even] & 1) == 0) even--;
            int t = nums[odd]; nums[odd] = nums[even]; nums[even] = t;
        }
        return nums;
    }
}
